import org.w3c.dom.ls.LSOutput;

public class Test {
    public static void main(String[] args) {
        System.out.println(facSum(3));
    }

    public static int facSum(int n) {
        int sum = 0;
        for (int i = 1; i <= n; i++) {
            sum += fac(i);
        }
        return sum;
    }





    public static void main1(String[] args) {
//        int num = 1234;
//        printNum(num);
//        System.out.println();
//        System.out.println(sum(num));

        //System.out.println(fib(6));

        //System.out.println(fac(5));

        System.out.println(sum1(10));
    }

    public static int sum1(int n) {             //递归 求1~n的和
        if (n == 1) {
            return 1;
        }
        return n + sum1(n - 1);
    }

    public static int fac(int n) {              //递归 求n的阶乘
        if (n == 1) {
            return 1;
        }
        return n * fac(n - 1);
    }

    public static int fib(int n) {              //递归 求斐波那契数列的第n项
        if (n == 1 || n == 2) {
            return 1;
        }
        return fib(n - 1) + fib(n - 2);
    }

    public static int sum(int n) {              //递归 输入一个非负整数，返回组成它的数字之和
        if (n < 10) {
            return n;
        }
        return n % 10 + sum(n / 10);
    }

    public static void printNum(int n) {        //递归 顺序打印数字的每一位
        if (n < 10) {
            System.out.print(n + " ");
            return;
        }
        printNum(n / 10);
        System.out.print(n % 10 + " ");
    }
}
